import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

export default new Vuex.Store({
	state: {
		toplistIds: [],
		nextId: ''
	},
	mutations: {
		initToplistIds(state, payload) {
			state.toplistIds = payload
		},
		nextId(state, payload) {
			for (let i = 0; i < state.toplistIds.length; i++) {
				if (state.toplistIds[i].id == payload) {
					if (state.toplistIds[i + 1].id) {
						state.nextId = state.toplistIds[i + 1].id
					} else {
						state.nextId = state.toplistIds[0].id
					}
				}
			}
		}
	}
})
